package org.schrag.sbbdroid;

import java.util.ArrayList;
import java.util.List;

import org.schrag.sbbdroid.data.*;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ConnectionList extends Activity {
	public static final String CONNECTIONS = "asdf";
	Connections model;
	ConnectionAdapter adapter = null;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_connections);
		
		model = (Connections)getIntent().getSerializableExtra(CONNECTIONS);

		ListView list = (ListView) findViewById(R.id.ListView);
		adapter = new ConnectionAdapter();
		list.setAdapter(adapter);
	}

	class ConnectionAdapter extends ArrayAdapter<Connection> {

		public ConnectionAdapter() {
			super(ConnectionList.this, android.R.layout.simple_list_item_1,
					model.getConnections());
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			View row = convertView;
			ConnectionWrapper wrapper = null;
			if (row == null) {
				LayoutInflater inflater = getLayoutInflater();
				row = inflater.inflate(R.layout.list_connections_row, null);
				wrapper = new ConnectionWrapper(row);
				row.setTag(wrapper);
			} else {
				wrapper = (ConnectionWrapper) row.getTag();
			}
			wrapper.populateFrom(this.getItem(position));
			return (row);
		}

	}
}
